﻿using System;
using System.Collections.Generic;

namespace DBXml
{
    public class Sort<T>
    {
        public T[] SelectionSort(T[] array)
        {
            return SelectionSort(array, 0, array.Length, Comparer<T>.Default);
        }

        public T[] SelectionSort(T[] array, int offset, int length, IComparer<T> comparer)
        {
            return SelectionSort(array, offset, length, comparer.Compare);
        }

        public T[] SelectionSort(T[] array, int offset, int length, Comparison<T> comparison)
        {
            int k;
            T temp;

            for (int i = 0; i < length; i++)
            {
                k = i;
                for (int j = i + 1; j < length; j++)
                {
                    if (comparison(array[j], array[k]) < 0)
                    {
                        k = j;
                    }
                }
                temp = array[i];
                array[i] = array[k];
                array[k] = temp;
            }
            return array;
        }
    }
}
